import unittest

import ddt
from CSV.DoCsv import ReadCsv
from Search import BingPage
from time import sleep
from selenium import webdriver

stream = open(r"E:\PageObject\AutomaticFrame\BingData.csv", "r", encoding="utf-8")
data = ReadCsv(stream)
@ddt.ddt
class TestBing(unittest.TestCase):
    def setUp(self):

        self.url = "http://cn.bing.com"
        # self.content = "习主席美国之行"
        # self.content = ReadCsv(stream)
        self.driver = webdriver.Chrome()
        self.BingSearch = BingPage(self.driver)

    @ddt.data(*data)    # 解包获取每个值
    def test_Bing(self, content):
        self.BingSearch.open(self.url)
        sleep(1)
        # self.BingSearch.search_content(self.content)
        self.BingSearch.search_content(content[0])
        sleep(1)
        self.BingSearch.search_click()
        sleep(2)
        # 断言
        self.assertTrue(content[1] in self.driver.page_source)

    def tearDown(self):
        self.BingSearch.quit()


if __name__ == "__main__":
    unittest.main(verbosity=2)
